from math import inf
from typing import List


class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        m, ans = inf, 0
        for p in prices:
            m = min(m, p)
            ans = max(ans, p - m)
        return ans